﻿using System.Configuration.Install;
using System.ServiceProcess;

namespace Elderos.Utils.Services
{
	/// <summary>
	/// Serves as a base class for the Windows Service installer.
	/// </summary>
	public class WindowsServiceInstaller : Installer
	{
		/// <summary>
		/// Service installer.
		/// </summary>
		private readonly ServiceInstaller _serviceInstaller;

		/// <summary>
		/// Service process installer.
		/// </summary>
		private readonly ServiceProcessInstaller _serviceProcessInstaller;

		/// <summary>
		/// Initializes a new instance of the <see cref="WindowsServiceInstaller"/> class.
		/// </summary>
		/// <param name="name">The name of service.</param>
		public WindowsServiceInstaller(string name)
		{
			_serviceProcessInstaller = new ServiceProcessInstaller
										   {
											   Account = ServiceAccount.LocalSystem,
											   Password = null,
											   Username = null,
										   };

			_serviceInstaller = new ServiceInstaller
									{
										DisplayName = name,
										ServiceName = name,
										StartType = ServiceStartMode.Automatic
									};

			Installers.AddRange(
				new Installer[]
					{
						_serviceProcessInstaller,
						_serviceInstaller
					});
		}
	}
}